package com.ruoyi.web.controller.customer;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.customer.domain.Order;
import com.ruoyi.customer.domain.Store;
import com.ruoyi.customer.service.IStoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 储存商品Controller
 * 
 * @author 王梦川
 * @date 2024-10-25
 */
@RestController
@RequestMapping("/customer/store")
public class OrderController extends BaseController
{
    @Autowired
    private IStoreService storeService;

    @PutMapping("/updateOrder")
    public AjaxResult update(@RequestBody Order order){
        return success(storeService.updateOrderForYmy(order));
    }

    /**
     * 查询储存商品列表
     */
    @PreAuthorize("@ss.hasPermi('customer:store:list')")
    @GetMapping("/list")
    public TableDataInfo list(Order order)
    {
        startPage();
        List<Order> list = storeService.selectStoreList(order);
        return getDataTable(list);
    }

    /**
     * 获取储存商品详细信息
     */
    @PreAuthorize("@ss.hasPermi('customer:store:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(storeService.selectStoreById(id));
    }

    /**
     * 新增储存商品
     */
    @PreAuthorize("@ss.hasPermi('customer:store:add')")
    @Log(title = "储存商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Store store) {
        return toAjax(storeService.insertStore(store));
    }

    /**
     * 修改储存商品
     */
    @PreAuthorize("@ss.hasPermi('customer:store:edit')")
    @Log(title = "储存商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Store store)
    {
        System.out.println(store);
        return toAjax(storeService.updateStore(store));
    }

    /**
     * 删除储存商品
     */
    @PreAuthorize("@ss.hasPermi('customer:store:remove')")
    @Log(title = "储存商品", businessType = BusinessType.DELETE)
	@DeleteMapping()
    public AjaxResult remove(@RequestBody Store store)
    {
        System.out.println(store);
        return toAjax(storeService.deleteStoreByIds(store));
    }
}
